<?php
/**
 * PartCategory.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-05-12 17:29:21
 * @modified    2023-05-12 17:29:21
 *
 */

namespace App\Models;

class PartCategory extends BaseModel
{
    protected $table = 'part_category';
    protected $primaryKey = 'id';

    public $timestamps = true;

    protected $fillable = [
        'name',
        'c_number',
        'type',
        'model',
        'uom',
        'sale_price',
        'out_price',
        'description',
        'status',
        'create_user_id'
    ];

    public function scopeByNumber($query, $number)
    {
        return $query->where('c_number', $number);
    }

    public function scopeByName($query, $name)
    {
        return $query->where('name', $name);
    }

    public function user()
    {
        return $this->belongsTo(UserModel::class, 'create_user_id');
    }

    public function inventories()
    {
        return $this->hasMany(Inventory::class, 'c_id', 'id');
    }

    public function user_inventories()
    {
        return $this->hasMany(UserInventory::class, 'c_id', 'id');
    }
}